#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* pthread_callback(void* arg){
    printf("线程正在运行\n");
    printf("线程ID = %ld\n",pthread_self()); //打印当前线程ID
    int num = 0;
    while(1){
        if (num > 4){
            break;
        }
        printf("线程正在运行\n");
        num++;
        sleep(1);
    }

    pthread_exit("线程退出"); //线程退出
}

int main(int argc, char const *argv[])
{
    pthread_t pthread = -1;
    int ret = 0;
    ret = pthread_create(&pthread, NULL, pthread_callback, NULL); //创建新的线程
    if (ret != 0){
        printf("pthread_create failed\n");
        return -1;
    }

    printf("pthread = %ld\n",pthread); //打印线程ID

    void* retval = NULL;
    pthread_join(pthread, &retval); //阻塞等待指定线程的退出
    printf("pthread_jion is %s\n",(char *)retval); //打印线程退出信息
    return 0;
}
